import javax.sound.midi.Soundbank;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

public class Demo2 {

    public static void main(String[] args) {
        BlockingQueue<Integer> blockingQueue = new LinkedBlockingQueue<>(1000);
        //生产者一个线程
        Thread producer = new Thread(() -> {
            int i = 0;
            while (true){
                try {
                    blockingQueue.put(i++);
                    System.out.println("生产：" + i);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });

        //消费者一个线程
        Thread customer = new Thread(() -> {
            while (true){
                try {
                    int cos = blockingQueue.take();
                    System.out.println("消费：" + cos);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });

        producer.start();
        customer.start();
    }
}
